package com.test;

import com.test.demo.WordCounting;
import org.activiti.engine.ProcessEngine;
import org.activiti.engine.ProcessEngineConfiguration;
import org.activiti.engine.task.Task;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

import java.util.List;

/**
 * Created by jl on 2018/11/26 0026
 */
@SpringBootApplication
public class Application implements CommandLineRunner {
    public static void main(String[] args) {
//        SpringApplication.run(Application.class, args);
        WordCounting.main(args);
        System.out.println("-----------GUI started-----------");
    }

    @Autowired
    private ProcessEngineConfiguration engineConf;

    @Override
    public void run(String... strings) throws Exception {
//        WordCounting.main(strings);
//        System.out.println("-----------GUI started-----------");
    }

    /**
     * 1：部署一个Activiti流程
     * 运行成功后，查看之前的数据库表，就会发现多了很多内容
     */
    private void createActTask() {
        ProcessEngine engine = engineConf.buildProcessEngine();
        engine.getRepositoryService()
                .createDeployment()
                .addClasspathResource("test.bpmn")
                .addClasspathResource("test.png")
                .deploy();
    }

    /**
     * 2：启动流程实例
     */
    private void startProcessInstance() {
        ProcessEngine engine = engineConf.buildProcessEngine();
        engine.getRuntimeService().startProcessInstanceById("myProcess_1:1:4");
    }

    /**
     * 完成请假申请
     */
    private void qingJia() {
        ProcessEngine engine = engineConf.buildProcessEngine();
        engine.getTaskService().complete("104");
    }

    /**
     * 小明学习的班主任bzr查询当前待执行的任务
     */
    private void queryCurTasks() {
        ProcessEngine engine = engineConf.buildProcessEngine();
        List<Task> tasks = engine.getTaskService()
                .createTaskQuery()
                .taskAssignee("bzr")
                .list();
        tasks.forEach(it -> System.out.println(it.getName()));
    }

    /**
     * 班主任完成任务
     */

    private void bzrCheck() {
        ProcessEngine engine = engineConf.buildProcessEngine();
        engine.getTaskService().complete("202");
    }

    /**
     * 教务处完成的任务
     */
    private void jwcCheck() {
        ProcessEngine engine = engineConf.buildProcessEngine();
        engine.getTaskService().complete("302");
    }
}
